<?php


namespace utils;


use PHPMailer\PHPMailer\PHPMailer;

class SendMail
{
    public static function sendMail($to_mail,$to_name,$subject,$content,$attachment){
        $mail = new PHPMailer();
        $mail->isSMTP();
        $mail->CharSet = "utf8";
        $mail->Host = config('rds.email.Host');
        $mail->SMTPAuth = true;
        $mail->Username = config('rds.email.Username');
        $mail->Password = config('rds.email.Password');
        $mail->SMTPSecure = "ssl";
        $mail->Port = config('rds.email.Port');

        $mail->setFrom(config('rds.email.From'),config('rds.email.FromName'));
        $mail->addAddress($to_mail,$to_name);
        foreach ($attachment as $k => $v){
            $mail->addAttachment($v['file'],$v['name']);

        }
        $mail->Subject = $subject;
        $mail->Body = $content;
        $mail->AltBody = $content;

        if(!$mail->send()){
            \think\facade\Log::error('邮件发送失败！');
            \think\facade\Log::error($mail->ErrorInfo);
            return false;
        } else {
            return true;
        }
    }
}